//
//  CZWelcomeViewController.swift
//  CZWeibo
//
//  Created by 左凯旭 on 16/8/12.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit
import SDWebImage
class CZWelcomeViewController: UIViewController {

    
    override func viewDidAppear(animated: Bool) {
        
        //更新约束
        self.headImageView.snp_updateConstraints { (make) in
            make.top.equalTo(view).offset(100)
        }
        
        
        //设置阻尼动画
           /*
            - 动画时间
            - 延迟时间
            - 阻尼系数 (阻尼系数 0-1  越小 弹性效果越大)
            - 起始速度
            - options
        */
        UIView.animateWithDuration(2, delay: 0.5, usingSpringWithDamping: 0.6, initialSpringVelocity: 0, options: [], animations: {
            
            //强制刷新UI
            self.view.layoutIfNeeded()
            
            }) { (_) in
                
                UIView.animateWithDuration(0.15, animations: {
                    self.label.alpha = 1
                    }, completion: { (_) in
                       
                        //发送通知给APPDelegate切换控制器
                        NSNotificationCenter.defaultCenter().postNotificationName(WBSWITCHROOTVCNOTIFICATION, object: nil)
                        
                })
                
        }
        
        
        
    }
    
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        setupUI()
    }

    
    //设置视图
    private func setupUI(){
        //添加控件
        view.addSubview(bigImageView)
        view.addSubview(headImageView)
        view.addSubview(label)
        
        
        //设置约束
        bigImageView.snp_makeConstraints { (make) in
            make.edges.equalTo(view).offset(UIEdgeInsetsZero)
        }
        
        headImageView.snp_makeConstraints { (make) in
            make.centerX.equalTo(view)
            make.top.equalTo(view).offset(400)
            make.size.equalTo(CGSize(width: 90,height: 90))
        }
        
        label.snp_makeConstraints { (make) in
            make.centerX.equalTo(view)
            make.top.equalTo(headImageView.snp_bottom).offset(16)
            
        }
        
        
    }
    
    
    //懒加载控件
    private lazy var bigImageView:UIImageView = UIImageView(imageName: "ad_background")
    
    //头像
    private lazy var headImageView: UIImageView = {
        let image = UIImageView()
        //设置图片
        image.cz_setImageWithString(CZUserAccountViewModel.shareTools.userAccount?.avatar_large, playholderImageName: "avatar_default_big")
        
        //切圆
        image.layer.cornerRadius = 45
        image.layer.masksToBounds = true
        
        return image
    }()
    
    //文字
    private lazy var label:UILabel = {
       let label = UILabel()
        
        label.text = "欢迎回来"
        label.font = UIFont.systemFontOfSize(18)
        label.textColor = UIColor.darkGrayColor()
        label.textAlignment = .Center
        label.alpha = 0
        
        return label
    }()
}










